home *** CD-ROM | disk | FTP | other *** search
Wrap
unit DrBobWiz; {$I-} {.$DEFINE WIZARD} interface uses {$IFDEF WIZARD} ShareMem, VirtIntf, ExptIntf, ToolIntf, {$ENDIF} Forms, DB, DBTables, SysUtils, StdCtrls, ExtCtrls, Controls, Classes, CheckLst; type TFormWizard = class(TForm) Bevel: TBevel; Notebook: TNotebook; ButtonNext: TButton; ButtonCancel: TButton; ButtonBack: TButton; Panel: TPanel; Image: TImage; ComboBoxAliases: TComboBox; CheckListFields: TCheckListBox; LabelFinish: TLabel; MemoSQL: TMemo; TheQuery: TQuery; EditTitle: TEdit; EditFileName: TEdit; GroupBox: TGroupBox; EditAction: TEdit; RadioPost: TRadioButton; procedure FormCreate(Sender: TObject); procedure FormShow(Sender: TObject); procedure ButtonStepClick(Sender: TObject); procedure Precondition(Sender: TObject); private procedure BuildSQL; public Title: String; {$IFDEF WIZARD} procedure Finish(var ToolServices: TIToolServices); {$ELSE} procedure Finish; {$ENDIF} end; implementation {$R *.DFM} procedure TFormWizard.FormShow(Sender: TObject); begin Title := Caption; ButtonStepClick(Sender) end; procedure TFormWizard.ButtonStepClick(Sender: TObject); begin if Sender IS TButton then NoteBook.PageIndex := NoteBook.PageIndex + (Sender AS TButton).Tag; ButtonBack.Enabled := NoteBook.PageIndex > 0; { first } if (NoteBook.PageIndex = 1) and ((Sender AS TButton).Tag = 1) then BuildSQL; Caption := Title+Format(' %d/%d',[NoteBook.PageIndex+1,NoteBook.Pages.Count]); if NoteBook.PageIndex < Pred(NoteBook.Pages.Count) then begin ButtonNext.Caption := '&Next >'; ButtonNext.ModalResult := mrNone end else { Finish } begin ButtonNext.Caption := '&Finish'; ButtonNext.ModalResult := mrOk end end; procedure TFormWizard.FormCreate(Sender: TObject); begin Session.GetAliasNames(ComboBoxAliases.Items) end; procedure TFormWizard.BuildSQL; var i: Integer; begin CheckListFields.Items.Clear; with TheQuery do begin if ComboBoxAliases.Text <> '' then DatabaseName := ComboBoxAliases.Text; SQL := MemoSQL.Lines; FieldDefs.Update { get info without executing TheQuery }; for i:=0 to Pred(FieldDefs.Count) do begin CheckListFields.Items.Add(FieldDefs[i].Name); { only select the "parameterised" fields in the Query } CheckListFields.Checked[i] := (Pos(UpperCase(':'+FieldDefs[i].Name),UpperCase(SQL.Text)) > 0) or (Pos(UpperCase(':"'+FieldDefs[i].Name)+'"',UpperCase(SQL.Text)) > 0) end end end {BuildSQL}; procedure TFormWizard.Precondition(Sender: TObject); begin ButtonNext.Enabled := EditFileName.Text <> '' end; procedure TFormWizard.Finish{$IFDEF WIZARD}(var ToolServices: TIToolServices){$ENDIF}; { do your Wizard execution here (modal result = mrOK) } var f: System.Text; Str: String; i: Integer; begin {$IFDEF WIZARD} if Assigned(ToolServices) then {$ENDIF} begin System.Assign(f,EditFileName.Text); Rewrite(f); writeln(f,'<HTML>'); writeln(f,'<BODY>'); writeln(f,'<H1>',EditTitle.Text,'</H1>'); writeln(f,'<HR>'); write(f,'<FORM ACTION="',EditAction.Text); if RadioPost.Checked then writeln(f,'" METHOD=POST>') else writeln(f,'" METHOD=GET>'); writeln(f,'<UL>'); with TheQuery do try if ComboBoxAliases.Text <> '' then DatabaseName := ComboBoxAliases.Text; Str := MemoSQL.Text; if Pos('WHERE ',UpperCase(Str)) > 0 then System.Delete(Str,Pos('WHERE ',UpperCase(Str)),Length(Str)); SQL.Text := Str; Open; for i:=0 to Pred(CheckListFields.Items.Count) do if CheckListFields.Checked[i] then begin writeln(f,'<LI>',CheckListFields.Items[i],':'); writeln(f,'<BR><SELECT NAME="',CheckListFields.Items[i],'">'); First; while not eof do begin writeln(f,'<OPTION VALUE="',FieldByName(CheckListFields.Items[i]).AsString, '"> ',FieldByName(CheckListFields.Items[i]).AsString); Next end; writeln(f,'</SELECT>'); writeln(f,'<P>') end; writeln(f,'</UL>'); writeln(f,'<CENTER>'); writeln(f,'<INPUT TYPE=RESET>'); writeln(f,'<INPUT TYPE=SUBMIT>'); writeln(f,'</FORM>'); writeln(f,'<HR>'); writeln(f,'<FONT SIZE=1>Generated by QueryBob (c) 1998 by Bob Swart (aka Dr.Bob - <A HREF="http://www.drbob42.com"TARGET=_top>www.drbob42.com</A>)</FONT>'); writeln(f,'</BODY>'); writeln(f,'</HTML>'); Close finally System.Close(f); end end end {Finish}; end.